<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ include file="../../../../header.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<link
	href="<%=basePath%>statics/resources/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css"
	rel="stylesheet">
<link href="<%=basePath%>bootstrap/css/bootstrap.min.css"
	rel="stylesheet">

<script
	src="<%=basePath%>statics/resources/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="<%=basePath%>bootstrap/js/bootstrap.min.js"></script>
<script
	src="<%=basePath%>statics/resources/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
#manage-form {
	display: table;
	margin: 0 auto;
}

.table-row {
	display: table-row;
	height: 32px;
}

.ui-input {
	width: 200px;
}

.table-row>* {
	display: table-cell;
	margin-left: 20px;
	vertical-align: middle;
}

.table-row>label {
	text-align: right;
}
</style>


</head>
<body style="align: center;">
	<div style="margin-top: 10px; margin-left: 30px;">
		<form id="manage-form" action="" class="nice-validator n-yellow"
			novalidate="novalidate" _lpchecked="1">

			<div id="base-form">
				
				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">用户名称</label>
						</div>
						<div class="ctn-wrap">

							<select style="width: 210px; height: auto;" class="ui-input"
								name="personId" id="usercode">
							</select>
						</div>
					</li>
				</ul>
				
				
				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">合同类型</label>
						</div>
						<div class="ctn-wrap">

							<select style="width: 210px; height: auto;" class="ui-input"
								name="personId" id="contractType">
								<option value="0">试用期合同</option>
								<option value="1">转正合同</option>
							</select>
						</div>
					</li>
				</ul>

				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">开始时间</label>
						</div>
						<div class="ctn-wrap">
							<input value="" class="ui-input" name="startTime" id="startTime"
								type="text">
						</div>
					</li>
				</ul>
				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">结束时间</label>
						</div>
						<div class="ctn-wrap">
							<input value="" class="ui-input" name="endTime" id="endTime"
								autocomplete="off" aria-required="true" type="text">
						</div>
					</li>
				</ul>

				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">入职时间</label>
						</div>
						<div class="ctn-wrap">
							<input value="" class="ui-input" name="officeDate"
								id="officeDate" autocomplete="off" aria-required="true"
								type="text">
						</div>
					</li>
				</ul>

				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">当前合同</label>
						</div>
						<div class="ctn-wrap" id="active">
							<input class="switch-simple-3" id="switch_active" type="checkbox"><label
								for="switch_active" class="green"></label>
						</div>
					</li>
				</ul>
			</div>
		</form>
	</div>

	<script type="text/javascript">
		var api = frameElement.api;
		var operate = api.data.operate;
		var rowid = api.data.rowid;
		var rowdata = api.data.rowdata;
		var CallBack = api.data.callback;
		$(function() {
			initPopBtns();
			if (operate == "edit") {
				$("#deptCode").val(rowdata.deptCode);
				$("#deptName").val(rowdata.deptName);
				console.log(rowdata.companyId);
				$("#companyId option").filter(function() {
					return $(this).text() == rowdata.companyId;
				}).prop("selected", true);
				$("#parentId option").filter(function() {
					return $(this).text() == rowdata.parentId;
				}).prop("selected", true);
				$("#codeLevel").val(rowdata.codeLevel);
				$("#endFlag").html(rowdata.endFlag);
				$("#cwzzFlag").html(rowdata.cwzzFlag);
				$("#xsFlag").html(rowdata.xsFlag);
				$("#cgFlag").html(rowdata.cgFlag);
				$("#devFlag").html(rowdata.devFlag);
				$("#principal").val(rowdata.principal);
				$("#telephone").val(rowdata.telephone);
				$("#fax").val(rowdata.fax);
				$("#active").html(rowdata.active);

			}
			$('input[type=checkbox]').attr("disabled", false);
		})
		function initPopBtns() {
			var btnname = "add" == operate ? [ "保存", "关闭" ] : [ "确定", "取消" ];
			api.button({
				id : "confirm",
				name : btnname[0],
				focus : true,
				callback : function(e) {
					var usercode = $("#usercode").val();
					var contractType = $("#contractType").val();
					var startTime = $("#startTime").val();
					var endTime = $("#endTime").val();
					var officeTime = $("#officeDate").val();
					var active = $("#active input").prop("checked");
					var currentContract;
					if(active==true){
						currentContract=1;
					}
					else{
						currentContract=0;
					}
					if (operate == "add") {
						$.ajax({
							url :  encodeURI("/contract/addContract"),
							type : 'POST',
							dataType : "json",
							data : {
								"personId" : usercode,
								"contractType" : contractType,
								"startTime" : startTime,
								"endTime" : endTime,
								"officeDate" : officeTime,
								"currentContract" :currentContract
								
							},
							async : false,
							success : function(data) {
								if (data.status == 200) {
									parent.Public.tips({
										content : "添加成功"
									})
									CallBack();
								} else {
									parent.Public.tips({
										type : 1,
										content : "添加失败:" + data.message
									})
								}
							}
						});
					} else {
						$.ajax({
							url : encodeURI("/dept/gridCUD?oper=edit"),
							type : "POST",
							data : {
								"id" : rowid,
								"deptCode" : deptCode,
								"deptName" : deptName,
								"companyId" : companyId,
								"parentId" : parentId,
								"codeLevel" : codeLevel,
								"endFlag" : endFlag,
								"cwzzFlag" : cwzzFlag,
								"xsFlag" : xsFlag,
								"cgFlag" : cgFlag,
								"devFlag" : devFlag,
								"principal" : principal,
								"telephone" : telephone,
								"fax" : fax,
								"active" : active,
							},
							async : false,//同步,坑爹啊。。
							success : function(data) {
								if (data.status == 200) {
									parent.Public.tips({
										content : "修改成功"
									})
									CallBack();
								} else {
									parent.Public.tips({
										type : 1,
										content : "修改失败:" + data.message
									})
								}
							}
						});
					}
				}
			}, {
				id : "cancel",
				name : btnname[1]
			})
		}
	</script>
	
	<script type="text/javascript">
	var primaryId;

	$.ajax({
		type : "POST",
		url : "getAllUserCode",
		success : function(data) {
			var content = data;
			$("#usercode").append(data);
		}
	});
	
	function initDate(startDateTimeId, endDateTimeId, officeDateTimeId) {
		var startDate;
		var endDate;
		startDateTimeId = "#" + startDateTimeId;
		endDateTimeId = "#" + endDateTimeId;
		officeDateTimeId = "#" + officeDateTimeId;
		$(startDateTimeId).datetimepicker({
			format : 'yyyy-mm-dd hh:ii:ss',
			language : "zh-CN",
			todayHighlight : true,
			autoclose : true,
			todayBtn : true,
			minDate : 0,
			onChangeDateTime : function(dp, $input) {
				startDate = $(startDateTimeId).val();
			},
			onClose : function(current_time, $input) {
				if (startDate > endDate) {
					$(startDateTimeId).val(endDate);
					startDate = endDate;
				}
			}
		});

		$(officeDateTimeId).datetimepicker({
			format : 'yyyy-mm-dd hh:ii:ss',
			language : "zh-CN",
			todayHighlight : true,
			autoclose : true,
			todayBtn : true,
			minDate : 0,
			onChangeDateTime : function(dp, $input) {
				startDate = $(officeDateTimeId).val();
			},
			onClose : function(current_time, $input) {
				if (startDate > endDate) {
					$(officeDateTimeId).val(endDate);
					startDate = endDate;
				}
			}
		});

		$(endDateTimeId).datetimepicker({
			format : 'yyyy-mm-dd hh:ii:ss',
			language : "zh-CN",
			autoclose : true,
			todayHighlight : true,
			todayBtn : true,
			onClose : function(current_time, $input) {
				endDate = $(endDateTimeId).val();
				if (startDate > endDate) {
					$(endDateTimeId).val(startDate);
					endDate = startDate;
				}
			}
		});
	}
	initDate("startTime","endTime","officeDate");
</script>
</body>
</html>